<?php

declare (strict_types=1);

namespace app\api\controller;

use app\api\service\UserService;
use app\helper\Result;

class User extends Auth
{
    /** 注册
     * @return \support\Response|\think\response\Json
     */
    public function register(UserService $userService)
    {
        $data = $this->request->post();
        $userService->register($data);
        return Result::success('注册成功');
    }

    /** 登录
     * @return \support\Response|\think\response\Json
     */
    public function login(UserService $userService)
    {
        $data = $this->request->post();
        $user = $userService->login($data);
        return Result::success('登录成功', $user);
    }

    /** 退出登录
     * @return \support\Response|\think\response\Json
     */
    public function logout()
    {
        $this->logoutUser();
        return Result::success();
    }

    /** 当前登录的用户信息
     * @return \support\Response|\think\response\Json
     */
    public function info()
    {
        return Result::success('ok', $this->user);
    }


}
